import logging
import sys

from logging.handlers import RotatingFileHandler

# logging.basicConfig(level = logging.DEBUG,format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s')

# https://www.jianshu.com/p/e96be02032f9

mylog1 = logging.getLogger("logggg1")
mylog2 = logging.getLogger("logggg2")


mylog1.setLevel(logging.DEBUG)  # 不起作用
mylog1.warning("ok1")

hand = logging.StreamHandler(stream=sys.stdout)
mylog1.addHandler(hand)
mylog1.setLevel(logging.DEBUG)
# print(dir(mylog1))
#fmt = logging.Formatter(fmt='%(asctime)s [%(threadName)s] [%(name)s] [%(levelname)s] %(filename)s[line:%(lineno)d] %(message)s')
fmt = logging.Formatter(fmt='%(asctime)s [%(process)d] [%(threadName)s(%(thread)d)] [%(name)s] [%(levelname)s(%(levelno)s)] %(pathname)s.%(filename)s[line:%(lineno)d, funcName:%(funcName)s] %(message)s')
hand.setFormatter(fmt)
mylog1.info("ok111")

# 增加一个文件日志
file_hand = RotatingFileHandler("log.txt",maxBytes = 1*1024,backupCount = 3, mode='a', encoding='utf-8')
mylog1.addHandler(file_hand)
file_hand.setFormatter(fmt)

mylog1.info("ok111")

# mylog2.setLevel(logging.DEBUG)
mylog2.info("ok2")
